package com.compass.controller;




import com.compass.entity.BaseProtocolDo;
import com.compass.entity.DubboDo;
import com.compass.service.ComponentService;


import com.compass.util.CopyProperties;

import com.compass.vo.ResponseMessage;
import com.compass.vo.TablePage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;



/**
 * Created with IntelliJ IDEA.
 * User: li
 * Date: 2019/3/24
 * Time: 17:27
 * PROJECT：compass
 * PACKAGE: com.compass
 *
 * @author:55324936@qq.com To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/component")
public class ComponentController {
    //可以理解 dubbo http redis mysql mq

    @Autowired
    ComponentService componentService;

    @RequestMapping("/componentPage")
    public ModelAndView component(){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("/component/componentPage");
        return modelAndView;
    }

    @RequestMapping("/componentList")
    public @ResponseBody
    TablePage componentList(HttpServletRequest httpServletRequest){
        return componentService.componentList(httpServletRequest);
        //total
        //rows 具体的数据
    }


    @RequestMapping("/addComponentPage")
    public ModelAndView addComponentPage(String interfaceType,HttpServletRequest httpServletRequest){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("zkAddress","47.105.55.243:2181");
        modelAndView.addObject("interfaceType",interfaceType);
        String viewName ="/component/"+interfaceType+"ComponentForm";
        BaseProtocolDo baseProtocolDo = componentService.getComponentById(httpServletRequest);
        if(null!= baseProtocolDo){
            CopyProperties.copyToModel(baseProtocolDo,modelAndView);
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    @RequestMapping("/saveComponent")
    public ModelAndView addComponent(HttpServletRequest httpServletRequest){
        ModelAndView modelAndView=new ModelAndView();
        componentService.saveComponent(httpServletRequest);
        modelAndView.setViewName("/component/componentPage");
        //一系列的新增，当然现在也没有数据库表

        return modelAndView;
    }
    @RequestMapping("/deleteComponent")
    public @ResponseBody
    ResponseMessage deleteComponent(HttpServletRequest httpServletRequest){
        return    componentService.deleteComponent(httpServletRequest);
    }


}
